package com.ziyun.erp.web.modules.goods.controller;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.ziyun.erp.modules.goods.entity.GoodsEntity;
import com.ziyun.erp.modules.goods.entity.GoodsRecommendEntity;
import com.ziyun.erp.modules.goods.service.GoodsRecommendService;
import com.ziyun.erp.modules.goods.service.GoodsService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 推荐商品信息表
 *
 * @author 'luqy'
 * @email 
 * @date 2018-12-07 10:04:47
 */
@RestController
@RequestMapping("goods/goodsrecommend")
public class GoodsRecommendController {
    @Autowired
    private GoodsRecommendService goodsRecommendService;
    @Autowired
    private GoodsService goodsService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("goods:goodsrecommend:list")
    public R list(@RequestBody Map<String, Object> params){
        PageUtils page = goodsRecommendService.queryPage(params); 
       List<GoodsEntity> goodsList =goodsService.selectGoodsList(params);
        return R.ok().put("page", page).put("goodsList",goodsList);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("goods:goodsrecommend:info")
    public R info(@PathVariable("id") Integer id){
        GoodsRecommendEntity goodsRecommend = goodsRecommendService.selectById(id);
        return R.ok().put("goodsRecommend", goodsRecommend);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("goods:goodsrecommend:save")
    public R save(@RequestBody GoodsRecommendEntity goodsRecommend){
		R result = goodsRecommendService.saveGoodsRecommendInfo(goodsRecommend);
        return result;
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("goods:goodsrecommend:update")
    public R update(@RequestBody GoodsRecommendEntity goodsRecommend){

        goodsRecommendService.updateByAll(goodsRecommend);//更新有值得数据
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("goods:goodsrecommend:delete")
    public R deleteUpdate(@RequestParam("id") Integer id){
        goodsRecommendService.deleteUpdate(id);

        return R.ok();
    }
    /**
     * 远程搜索查询商品goodsId
     */
    @RequestMapping("/search")
    public R search(@RequestBody Map<String,Object> params){
    	 List<GoodsEntity> goodsList =goodsService.selectGoodsList(params);
       
        return R.ok().put("goodsList", goodsList);
    }
}
